﻿using Common;
using Common.FrontEnd;
using FrontEnd;
using Linguist.Acoustic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Linguist.Flat
{
    /// <summary>
    /// Represents a hmmState in an SentenceHMMS
    /// IScoreProvider -  is implemented without using interface derivation
    /// </summary>
    public class HMMStateState : SentenceHMMState, ISerializable, IHMMSearchState     
    
    {
        private IHMMState hmmState;
        private Boolean _isEmitting;


        /**
        /// Creates a HMMStateState
         *
        /// @param parent   the parent of this state
        /// @param hmmState the hmmState associated with this state
         */
        public HMMStateState(SentenceHMMState parent, IHMMState hmmState) 
            : base("S", parent, hmmState.getState())
        {
            this.hmmState = hmmState;
            this._isEmitting = hmmState.isEmitting();
        }


        /**
        /// Gets the hmmState associated with this state
         *
        /// @return the hmmState
         */
        public IHMMState getHMMState() 
        {
            return hmmState;
        }


        /**
        /// Determines if this state is an emitting state
         *
        /// @return true if the state is an emitting state
         */
        public Boolean isEmitting() 
        {
            return _isEmitting;
        }


        /**
        /// Retrieves a short label describing the type of this state. Typically, subclasses of SentenceHMMState will
        /// implement this method and return a short (5 chars or less) label
         *
        /// @return the short label.
         */
        public String getTypeLabel() 
        {
            return "HMM";
        }

    
        /**
        /// Calculate the acoustic score for this state
         *
        /// @return the acoustic score for this state
         */
        public float getScore(IData feature) 
        {
            return hmmState.getScore(feature);
        }


        /**
        /// Returns the state order for this state type
         *
        /// @return the state order
         */
        override
        public int getOrder() {
            return _isEmitting ? 6 : 0;
        }


	    public float[] getComponentScore(IData feature) {
		    return hmmState.calculateComponentScore(feature);
	    }

        IHMMState IHMMSearchState.getHMMState()
        {
            throw new NotImplementedException();
        }

        ISearchStateArc[] ISearchState.getSuccessors()
        {
            if (successorArray == null)
            {
                successorArray = arcs.Values.ToArray();
            }
            return successorArray;
        }

        bool ISearchState.isEmitting()
        {
            return this.isEmitting();
        }

        bool ISearchState.isFinal()
        {
            throw new NotImplementedException();
        }

        string ISearchState.toPrettyString()
        {
            throw new NotImplementedException();
        }

        string ISearchState.getSignature()
        {
            throw new NotImplementedException();
        }

        WordSequence getWordHistory()
        {
            throw new NotImplementedException();
        }

        object ISearchState.getLexState()
        {
            throw new NotImplementedException();
        }

        int ISearchState.getOrder()
        {
            throw new NotImplementedException();
        }

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            throw new NotImplementedException();
        }
    }
}
